
Page({
    data: {
       
        header:{},
        userInfo:{},
        tieziList:[],
        select:20,
        arr1:[],
        arr2:[],
        pageNum:1,
        current:1,
        pagesize:20,
        pages:1

    },
    onLoad:function(){
     getApp().getUserInfo().then(res=>{
      var header={
             'openid':res.openid, //公用请求头
             'content-type': 'application/json'
         }
       this.setData({
        userInfo:res,
        header:header
       })  

       this.getTiezi(20);
     })
    },
     //上拉加载更多
    onReachBottom:function(){
        console.log('加载更多')
        this.setData({
          current:this.data.current+1
        })
         if (this.data.current<=this.data.pages) {
          this.getTiezi();
         }  
    },
    //帖子
    getTiezi:function () {
        var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/articles/getList?openid='+this.data.userInfo.openid+'&status='+this.data.select+'&current='+this.data.current+'&pagesize='+this.data.pagesize,
            method:"GET",
            header: this.data.header,
            success: function(res) {

           
             _self.setData({
               
                tieziList:_self.data.tieziList.concat(res.data.obj.list),
                pages:res.data.obj.pages
             })
      
         }
       })
    },
    //删除帖子
    deleteTiezi:function (e) {
        var id=e.target.dataset.code;  
        console.log(id)
        var _self=this;
        wx.showModal({
          title: '提示',
          content: '是否确定删除?',
          success (res) {
            if (res.confirm) {
              console.log('用户点击确定')
               wx.request({
                    url:getApp().globalData.baseUrl+'/wx/articles/update',
                    method:"POST",
                    header: _self.data.header,
                    data:{
                       "id":id,
                       "yn":0,
                       'openid':_self.data.userInfo.openid
                    },
                    success: function(res) {
                    _self.getTiezi();
                     
                 }
               })
            } else if (res.cancel) {
              console.log('用户点击取消')

            }
          }
        })

       
       
    },
    //更新帖子
    updateTiezi:function (e) {
       var id=e.target.dataset.code;
       wx.navigateTo({
            url:'/pages/changeSheQu/changeSheQu?id='+id
        })
    },
    turnDetail:function(e){
      console.log(e)
      if (e.currentTarget.dataset.code.status==10) {
        return
      }
      wx.navigateTo({
            url: '/pages/communityDetail/communityDetail?id='+e.currentTarget.dataset.code.id
        })
    },
     allSend:function (e) {
      console.log(e.currentTarget.dataset.code)
      var code=e.currentTarget.dataset.code;
      this.setData({
        select:code,
        current:1,
        tieziList:[]
      })
      this.getTiezi(code);
      // if (code==20) {
      //   this.setData({    
      //     tieziList:this.data.arr1
      //    })
      // }else if(code==10){
      //    this.setData({    
      //     tieziList:this.data.arr2
      //    })
      // }
       
    }
});